package com.ssm.service.impl;

import com.ssm.dao.FileDao;
import com.ssm.dao.UserDao;
import com.ssm.entity.File;
import com.ssm.entity.User;
import com.ssm.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 小灰灰 on 2017/7/31.
 */
@Service("fileService")
public class FileServiceImpl implements FileService {

    @Autowired(required = false)
    private FileDao fileDao;
    @Autowired(required = false)
    private UserDao userDao;

    //判断文件是否已经存在
    public boolean exists(String fileName, User user) {
        List<File> fileList = fileDao.queryByUserId(user.getId());
        /*File file = fileList.*/

       /* if (file != null){
        return true;
        }*/
        return false;
    }

    public File mkdirs() {

        return null;
    }

    public boolean exists(String fileName) {
        return false;
    }

    public void addToDatabase(File file){
        fileDao.addFile(file.getFileName(),file.getCreateTime(),file.getAlterTime(),file.getUserId());
      /*  fileDao.queryByName(file.getFileName());
        if(file){*/
    }

    public  List<File> queryAllDoc(){
       List<File> fileList= fileDao.queryAll();
        /*fileList=fileDao.queryAll();*/
        return fileList ;
    }

    public File queryByFileid(int fileId) {
        File file= fileDao.queryById(fileId);
        return file;

    }

    public void deleteDoc( int fileId){
        fileDao.deleteFile(fileId);
    };


    public List<File> queryByKeyName(String keyName){
        List<File> file= fileDao.queryByKeyName(keyName);
        return file;
    }

    public List<File> queryAll(){
        return fileDao.queryAll();
    }

    public List<File> queryByUserName(String username) {

        User user = userDao.queryByName(username);
        return fileDao.queryByUserId(user.getId());
    }
}
